package fun.tan90.easy.binlog.manager.rest;


import fun.tan90.easy.binlog.manager.model.cmd.MetricThreadQueryCmd;
import fun.tan90.easy.binlog.manager.service.MetricService;
import fun.tan90.easy.binlog.manager.model.cmd.MetricCpuQueryCmd;
import fun.tan90.easy.binlog.manager.model.cmd.MetricJvmQueryCmd;
import fun.tan90.easy.binlog.manager.model.vo.MetricCacheStatsVo;
import fun.tan90.easy.binlog.manager.model.vo.MetricCpuLineChartVo;
import fun.tan90.easy.binlog.manager.model.vo.MetricJvmLineChartVo;
import fun.tan90.easy.binlog.manager.model.vo.MetricThreadLineChartVo;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * description TODO
 * company 铁人科技
 *
 * @author 陈浩杰
 * @date 2023/7/13 11:08
 */
@Slf4j
@RestController
@RequestMapping("metric")
public class MetricController {

    @Resource
    MetricService metricService;

    /**
     * jvm 内存
     *
     * @param queryCmd
     * @return
     */
    @PostMapping("jvm")
    public List<MetricJvmLineChartVo> jvm(@RequestBody @Validated MetricJvmQueryCmd queryCmd) {
        return metricService.jvm(queryCmd);
    }

    /**
     * jvm 百分比
     *
     * @param workId
     * @param jvmType
     * @return
     */
    @GetMapping("jvm-percent")
    public Double jvmPercent(String workId, String jvmType) {
        return metricService.jvmPercent(workId, jvmType);
    }

    /**
     * cpu 使用情况
     *
     * @param queryCmd
     * @return
     */
    @PostMapping("cpu")
    public List<MetricCpuLineChartVo> cpu(@RequestBody @Validated MetricCpuQueryCmd queryCmd) {
        return metricService.cpu(queryCmd);
    }

    /**
     * 线程使用情况
     *
     * @param queryCmd
     * @return
     */
    @PostMapping("thread")
    public List<MetricThreadLineChartVo> thread(@RequestBody @Validated MetricThreadQueryCmd queryCmd) {
        return metricService.thread(queryCmd);
    }

    /**
     * 缓存统计信息
     *
     * @param workId
     * @return
     */
    @GetMapping("cache-stats")
    public List<MetricCacheStatsVo> cacheStats(String workId) {
        return metricService.cacheStats(workId);
    }
}
